// LiteLoader-AIDS automatic generated
/// <reference path="c:\Users\Yoyo\AppData\mclib/dts/helperlib/src/index.d.ts"/> 

ll.registerPlugin(
    /* name */ "限制生物",
    /* introduction */ "限制生物自然生成的插件",
    /* version */[0, 0, 1],
    /* otherInformation */ {
        author: 'Yoyo'
    }
);


const CONFIG = new JsonConfigFile('./plugins/Yoyo/limitSpawned/config.json', JSON.stringify({
    areas: [
        { pos1: { x: 7045, y: 55, z: 4230, dimid: 0 }, pos2: { x: 6404, y: 80, z: 3446, dimid: 0 }, filter: ["minecraft:zombie"] },
        // pos1 和 pos2 是3维两个坐标    filter里面是支持的过滤不清楚的生物类型
        { pos1: { x: 101, y: 0, z: 101, dimid: 0 }, pos2: { x: 200, y: 200, z: 200, dimid: 0 }, filter: ["minecraft:zombie"] },
    ]
}));


mc.listen("onMobSpawned", (entity, pos) => {

    let areas = CONFIG.get('areas');
    for (let area of areas) {
        let isPointIn = pointInRegion(area.pos1, area.pos2, pos);
        if (!isPointIn) continue;
        if (area.filter.includes(entity.type)) continue;//过滤掉指定生物
        entity.remove();
    }
});


// 判断坐标是否在区域内
function pointInRegion(startPoint, endPoint, point) {
    if (startPoint.dimid !== endPoint.dimid || startPoint.dimid !== point.dimid) return false; // 不在同一维度

    const adjustedStartX = Math.min(startPoint.x, endPoint.x);
    const adjustedEndX = Math.max(startPoint.x, endPoint.x);
    const adjustedStartY = Math.min(startPoint.y, endPoint.y);
    const adjustedEndY = Math.max(startPoint.y, endPoint.y);
    const adjustedStartZ = Math.min(startPoint.z, endPoint.z);
    const adjustedEndZ = Math.max(startPoint.z, endPoint.z);

    const inRangeX = point.x >= adjustedStartX && point.x <= adjustedEndX;
    const inRangeY = point.y >= adjustedStartY && point.y <= adjustedEndY;
    const inRangeZ = point.z >= adjustedStartZ && point.z <= adjustedEndZ;

    return inRangeX && inRangeY && inRangeZ;
}